package org.rcgwt.client.ui.calendar.event;

import java.util.Date;

import com.google.gwt.event.shared.GwtEvent;

/**
 * A event that signals the renderer that the model has been modified (with a
 * bitmask structure)
 * 
 * @author Elian ORIOU
 * 
 */

public class ModelChangedEvent extends GwtEvent<ModelChangedHandler> {

	private static final GwtEvent.Type<ModelChangedHandler> TYPE = new GwtEvent.Type<ModelChangedHandler>();
	private Date date;
	private int elementType;

	public ModelChangedEvent(int element, Date d) {
		setDate(d);
		setElementType(element);
	}

	@Override
	protected void dispatch(ModelChangedHandler handler) {
		handler.onModelChangedEvent(this);
	}

	@Override
	public com.google.gwt.event.shared.GwtEvent.Type<ModelChangedHandler> getAssociatedType() {
		return TYPE;
	}

	public static void fire(HasModelChangedHandlers source, int element, Date d) {
		if (TYPE != null) {
			ModelChangedEvent event = new ModelChangedEvent(element, d);
			source.fireEvent(event);
		}
	}

	public static GwtEvent.Type<ModelChangedHandler> getType() {
		return TYPE;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Date getDate() {
		return date;
	}

	public int getElementType() {
		return elementType;
	}

	public void setElementType(int element) {
		this.elementType = element;
	}

	@Override
	public String toString() {
		return "ModelChangedEvent [date=" + date + ", element=" + elementType
				+ "]";
	}
}
